<template>
  <div class="body">
    <div class="menu">
      <h1 class="menu_title">2018周报管理</h1>
      <div class="department">
        <span style="color: #fff">部门：</span>
        <el-select @change="changeDept" style="width: 100px" v-model="departmentDefault" filterable>
          <el-option
                  v-for="item in department"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
          </el-option>
        </el-select>
      </div>
      <!--<div style="display: flex;justify-content: center;margin-top: 20px">
        <el-button size="mini" type="info" round @click="addWeeklyPopup = true">添加周报</el-button>
        <el-button size="mini" type="info" round @click="confirmDel">删除周报</el-button>
      </div>-->
      <el-menu
              :default-active="menuDefaultId"
              @select="handleSelect"
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose"
              background-color="#545c64"
              text-color="#fff"
              :unique-opened=true
              active-text-color="#ffd04b"
              style="border: 0;text-align: center">
        <el-submenu v-for="(item,index) in menu" :index="index+'1'">
          <template slot="title">
            <span>{{item}}月份</span>
          </template>
          <el-menu-item-group>
            <el-menu-item v-for="content in menuList" v-if="content.monthWeek==item" :index="content.id">
              {{content.weeklyId}}
            </el-menu-item>
          </el-menu-item-group>
        </el-submenu>
      </el-menu>
    </div>
    <div class="content" v-show="showContent">
      <div class="content_header">
        区域产品中心 {{projectDetail.weeklyId}} 工作汇报
        <el-button type="primary" style="margin-left: 20px;" @click="submit">保存修改
        </el-button>
        <el-button type="primary" style="margin-left: 20px;" @click="uploadWeekly">导出周报</el-button>
      </div>
      <div class="wrapper">
        <div class="content_left">
          <div class="title">本周工作重点</div>
          <div style="display: flex;justify-content: flex-start">
            <div class="main">
              <div>主要工作事项（必填）</div>
              <div style="border-right: 1px solid rgb(235, 235, 235);width: 100%">
                <div class="block">
                  <template v-if="projectDetail.deptName=='技术支持部'">
                    <p style="text-align: left;padding:10px 0 10px 10px;font-size: 16px">现场支持或商务支持情况
                      <el-button
                              @click="addConfirm('01','03')"
                              style="margin-left: 13px"
                              type="text"
                              size="mini">
                        添加项目
                      </el-button>
                    </p>
                    <ul v-for="(item,index) in projectList"
                        v-if="item.typeFlag == '03' && item.workFlag=='01'">
                      <div class="projectName">
                        <p style="max-width: 250px">{{item.projectId}}、{{item.name}}</p>
                        <div style="padding-left: 10px">
                          <el-button
                                  @click="projectNameModify(index,'01','03')"
                                  type="text"
                                  size="mini">
                            修改
                          </el-button>
                          <!--<el-button
                                  @click="projectNameDeleteConfirm(index)"
                                  type="text"
                                  size="mini">
                            删除
                          </el-button>-->
                        </div>
                      </div>
                      <li v-for="(i,idx) in item.content">
                        <p>{{item.projectId}}.{{idx+1}} {{i.detail}}</p>
                      </li>
                    </ul>
                  </template>
                  <template v-if="projectDetail.deptName=='技术支持部'">
                    <p style="text-align: left;padding:10px 0 10px 10px;font-size: 16px">重点项目关键节点
                      <el-button
                              @click="addConfirm('01','04')"
                              style="margin-left: 61px"
                              type="text"
                              size="mini">
                        添加项目
                      </el-button>
                    </p>
                    <ul v-for="(item,index) in projectList"
                        v-if="item.typeFlag == '04' && item.workFlag=='01'">
                      <div class="projectName">
                        <p style="max-width: 250px">{{item.projectId}}、{{item.name}}</p>
                        <div style="padding-left: 10px">
                          <el-button
                                  @click="projectNameModify(index,'01','04')"
                                  type="text"
                                  size="mini">
                            修改
                          </el-button>
                          <!--<el-button
                                  @click="projectNameDeleteConfirm(index)"
                                  type="text"
                                  size="mini">
                            删除
                          </el-button>-->
                        </div>
                      </div>
                      <li v-for="(i,idx) in item.content">
                        <p>{{item.projectId}}.{{idx+1}} {{i.detail}}</p>
                      </li>
                    </ul>
                  </template>
                  <template v-if="projectDetail.deptName=='研发部'">
                    <p style="text-align: left;padding:10px 0 10px 10px;font-size: 16px">立项项目
                      <el-button
                              @click="addConfirm('01','01')"
                              style="margin-left: 125px"
                              type="text"
                              size="mini">
                        添加项目
                      </el-button>
                    </p>
                    <ul v-for="(item,index) in projectList"
                        v-if="item.typeFlag == '01' && item.workFlag=='01'">
                      <div class="projectName">
                        <p style="max-width: 250px">{{item.projectId}}、{{item.name}}</p>
                        <div style="padding-left: 10px">
                          <el-button
                                  @click="projectNameModify(index,'01','01')"
                                  type="text"
                                  size="mini">
                            修改
                          </el-button>
                          <!--<el-button
                                  @click="projectNameDeleteConfirm(index)"
                                  type="text"
                                  size="mini">
                            删除
                          </el-button>-->
                        </div>
                      </div>
                      <li v-for="(i,idx) in item.content">
                        <p>{{item.projectId}}.{{idx+1}} {{i.detail}}</p>
                      </li>
                    </ul>
                  </template>
                  <template v-if="projectDetail.deptName=='研发部'">
                    <p style="text-align: left;padding:10px 0 10px 10px;font-size: 16px">非立项项目
                      <el-button
                              @click="addConfirm('01','02')"
                              style="margin-left: 110px"
                              type="text"
                              size="mini">
                        添加项目
                      </el-button>
                    </p>
                    <ul v-for="(item,index) in projectList"
                        v-if="item.typeFlag == '02' && item.workFlag=='01'">
                      <div class="projectName">
                        <p style="max-width: 250px">{{item.projectId}}、{{item.name}}</p>
                        <div style="padding-left: 10px">
                          <el-button
                                  @click="projectNameModify(index,'01','02')"
                                  type="text"
                                  size="mini">
                            修改
                          </el-button>
                          <!--<el-button
                                  @click="projectNameDeleteConfirm(index)"
                                  type="text"
                                  size="mini">
                            删除
                          </el-button>-->
                        </div>
                      </div>
                      <li v-for="(i,idx) in item.content">
                        <p>{{item.projectId}}.{{idx+1}} {{i.detail}}</p>
                      </li>
                    </ul>
                  </template>
                </div>
              </div>
            </div>
            <div class="sum_up">
              <div style="border-right:1px solid rgb(235, 235, 235); width: 100%">
                <p>一周总结（必填）</p>
                <div style="padding: 10px 0 10px 25px;">
                  <div class="project">一、项目进度情况：('<>'中的内容<span style="color: red">标红</span>)</div>
                  <div class="project_detail">
                    <ul v-for="(item,index) in projectList">
                      <li v-if="projectDetail.deptName == item.deptName && item.workFlag=='01'">
                        <p>{{index+1}}.{{item.name}}</p>
                        <el-input
                                type="textarea"
                                :rows="4"
                                placeholder="请输入内容"
                                v-model="item.summary"
                                @blur="submit">
                        </el-input>
                      </li>
                    </ul>
                  </div>
                  <div class="project" style="padding-top: 10px;">二.OA需求：</div>
                  <div class="project_detail">
                    <el-input
                            type="textarea"
                            :rows="4"
                            placeholder="请输入内容"
                            @blur="submit"
                            v-model="projectDetail.oa">
                    </el-input>
                  </div>
                  <div class="project" style="padding-top: 10px;">三.需协调的问题：</div>
                  <div class="project_detail">
                    <el-input
                            type="textarea"
                            :rows="4"
                            placeholder="请输入内容"
                            @blur="submit"
                            v-model="projectDetail.coordinate">
                    </el-input>
                  </div>
                  <!--<div class="submit" style="padding-top: 20px;">
                    <el-button type="primary" style="margin-left: -10px;" @click="submit">保存修改
                    </el-button>
                  </div>-->
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="content_right">
          <div class="title">下周重点工作计划</div>
          <div class="ready">
            <div>主要工作事项（必填）</div>
            <div style="border-right: 1px solid rgb(235, 235, 235);width: 100%">
              <div class="block">
                <template v-if="projectDetail.deptName=='技术支持部'">
                  <p style="text-align: left;padding:10px 0 10px 10px;font-size: 16px">现场支持或商务支持情况
                    <el-button
                            @click="addConfirm('02','03')"
                            style="margin-left: 13px"
                            type="text"
                            size="mini">
                      添加项目
                    </el-button>
                  </p>
                  <ul v-for="(item,index) in projectList"
                      v-if="item.typeFlag == '03' && item.workFlag=='02'">
                    <div class="projectName">
                      <p style="max-width: 250px">{{item.projectId}}、{{item.name}}</p>
                      <div style="padding-left: 10px">
                        <el-button
                                @click="projectNameModify(index,'02','03')"
                                type="text"
                                size="mini">
                          修改
                        </el-button>
                        <!--<el-button
                                @click="projectNameDeleteConfirm(index)"
                                type="text"
                                size="mini">
                          删除
                        </el-button>-->
                      </div>
                    </div>
                    <li v-for="(i,idx) in item.content">
                      <p>{{item.projectId}}.{{idx+1}} {{i.detail}}</p>
                      <div class="block">
                        <el-date-picker
                                style="width: 150px"
                                size="mini"
                                type="date"
                                v-model="i.time"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                placeholder="预计完成时间">
                        </el-date-picker>
                      </div>
                    </li>
                  </ul>
                </template>
                <template v-if="projectDetail.deptName=='技术支持部'">
                  <p style="text-align: left;padding:10px 0 10px 10px;font-size: 16px">重点项目关键节点
                    <el-button
                            @click="addConfirm('02','04')"
                            style="margin-left: 61px"
                            type="text"
                            size="mini">
                      添加项目
                    </el-button>
                  </p>
                  <ul v-for="(item,index) in projectList"
                      v-if="item.typeFlag == '04' && item.workFlag=='02'">
                    <div class="projectName">
                      <p style="max-width: 250px">{{item.projectId}}、{{item.name}}</p>
                      <div style="padding-left: 10px">
                        <el-button
                                @click="projectNameModify(index,'02','04')"
                                type="text"
                                size="mini">
                          修改
                        </el-button>
                        <!--<el-button
                                @click="projectNameDeleteConfirm(index)"
                                type="text"
                                size="mini">
                          删除
                        </el-button>-->
                      </div>
                    </div>
                    <li v-for="(i,idx) in item.content">
                      <p>{{item.projectId}}.{{idx+1}} {{i.detail}}</p>
                      <div class="block">
                        <el-date-picker
                                style="width: 150px"
                                size="mini"
                                type="date"
                                v-model="i.time"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                placeholder="预计完成时间">
                        </el-date-picker>
                      </div>
                    </li>
                  </ul>
                </template>
                <template v-if="projectDetail.deptName=='研发部'">
                  <p style="text-align: left;padding:10px 0 10px 10px;font-size: 16px">立项项目
                    <el-button
                            @click="addConfirm('02','01')"
                            style="margin-left: 125px"
                            type="text"
                            size="mini">
                      添加项目
                    </el-button>
                  </p>
                  <ul v-for="(item,index) in projectList"
                      v-if="item.typeFlag == '01' && item.workFlag=='02'">
                    <div class="projectName">
                      <p style="max-width: 250px">{{item.projectId}}、{{item.name}}</p>
                      <div style="padding-left: 10px">
                        <el-button
                                @click="projectNameModify(index,'02','01')"
                                type="text"
                                size="mini">
                          修改
                        </el-button>
                        <!--<el-button
                                @click="projectNameDeleteConfirm(index)"
                                type="text"
                                size="mini">
                          删除
                        </el-button>-->
                      </div>
                    </div>
                    <li v-for="(i,idx) in item.content">
                      <p>{{item.projectId}}.{{idx+1}} {{i.detail}}</p>
                      <div class="block">
                        <el-date-picker
                                style="width: 150px"
                                size="mini"
                                type="date"
                                v-model="i.time"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                placeholder="预计完成时间">
                        </el-date-picker>
                      </div>
                    </li>
                  </ul>
                </template>
                <template v-if="projectDetail.deptName=='研发部'">
                  <p style="text-align: left;padding:10px 0 10px 10px;font-size: 16px">非立项项目
                    <el-button
                            @click="addConfirm('02','02')"
                            style="margin-left: 110px"
                            type="text"
                            size="mini">
                      添加项目
                    </el-button>
                  </p>
                  <ul v-for="(item,index) in projectList"
                      v-if="item.typeFlag == '02' && item.workFlag=='02'">
                    <div class="projectName">
                      <p style="max-width: 250px">{{item.projectId}}、{{item.name}}</p>
                      <div style="padding-left: 10px">
                        <el-button
                                @click="projectNameModify(index,'02','02')"
                                type="text"
                                size="mini">
                          修改
                        </el-button>
                        <!--<el-button
                                @click="projectNameDeleteConfirm(index)"
                                type="text"
                                size="mini">
                          删除
                        </el-button>-->
                      </div>
                    </div>
                    <li v-for="(i,idx) in item.content">
                      <p>{{item.projectId}}.{{idx+1}} {{i.detail}}</p>
                      <div class="block">
                        <el-date-picker
                                style="width: 150px"
                                size="mini"
                                type="date"
                                v-model="i.time"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                placeholder="预计完成时间">
                        </el-date-picker>
                        <!-- <el-col :span="16">
                           <el-input v-model="i.time" size="mini" placeholder="预计完成时间"></el-input>
                         </el-col>-->
                      </div>
                    </li>
                  </ul>
                </template>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!--添加周报弹窗-->
    <el-dialog
            title="请选择时间"
            :visible.sync="addWeeklyPopup"
            width="30%">
      <div class="block">
        <el-date-picker
                v-model="newWeekly"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addWeeklyPopup = false">取 消</el-button>
        <el-button type="primary" @click="addWeekly">确 定</el-button>
      </span>
    </el-dialog>
    <!--添加项目弹窗-->
    <el-dialog
            title="编辑项目"
            :visible.sync="dialogVisible"
            width="40%">
      <div style="display: flex;justify-content: left;align-items: center">
        <span style="min-width: 70px">项目名称：</span>
        <el-input v-model="newProjectName" placeholder="请输入新的项目名称"></el-input>
      </div>
      <div style="margin-top: 15px;display: flex;justify-content: left;align-items: flex-start">
        <span style="min-width: 70px">项目详情：</span><br>
        <div style="width: 100%">
          <el-input style="margin-bottom: 10px" v-for="(item,index) in newProjectDetail"
                    @focus="inputDefault=index"
                    v-model="item.detail" size="small" placeholder="请输入详情"></el-input>
        </div>
      </div>
      <el-button type="primary" size="small" style="margin: 15px 0 0 70px" @click="addNewProjectDetail">添加详情
      </el-button>
      <el-button type="primary" size="small" style="margin: 15px 0 0 15px" @click="delNewProjectDetail">删除详情
      </el-button>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addProject">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 删除周报弹窗-->
    <el-dialog
            title="删除周报"
            :visible.sync="delWeeklyPopup"
            width="30%">
      <span style="font-size: 16px">确认要删除 <span style="color: red">{{weeklyIdDefault}}</span> 吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="delWeeklyPopup = false">取 消</el-button>
        <el-button type="primary" @click="delWeekly">确 定</el-button>
      </span>
    </el-dialog>
    <!--删除项目弹窗-->
    <el-dialog
            title="删除项目"
            :visible.sync="delProjectPopup"
            width="30%">
      <span style="font-size: 16px">确认要删除 <span style="color: red">{{projectNameDefault}}</span> 吗？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="delProjectPopup = false">取 消</el-button>
        <el-button type="primary" @click="projectNameDelete">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        showContent: false,
        addOrEdit: true,
        department: [{
          value: '研发部',
          label: '研发部'
        }, {
          value: '技术支持部',
          label: '技术支持部'
        }],
        menuDefaultId: '',
        getMenuList: [],
        addWeeklyPopup: false,
        delWeeklyPopup: false,
        newWeekly: '',
        departmentDefault: '研发部',
        weeklyIdDefault: '',
        inputDefault: '',
        idDefault: 0,
        projectNameDefault: '',
        projectIdDefault: '',
        workFlag: '',
        typeFlag: '',
        dateTime: '',
        dialogVisible: false,
        projectSummary: '',
        coordination: '',
        newProjectName: '',
        newProjectDetail: [
          {detail: '', time: ''}
        ],
        delProjectPopup: false,
        OANeed: '',
        defaultSelected: '2017',
        menu: [],
        menuList: [],
        projectList: [],
        projectDetail: [],
      }
    },
    created() {
      this.getWeeklyList()
      // this.getProjectContent(true)
    },
    methods: {
      changeDept() {
        this.weeklyIdDefault = ''
        this.getWeeklyList()
      },
      sortNumber(a, b) {
        return a - b
      },
      getWeeklyList() {
        this.menuList = []
        let time = new Date().format('yyyy-MM-dd').split('-').join('')

        let url = this.webUrl + '/weekly/v1/weekly/getList.do?year=' + '2018' + '&deptName=' + this.departmentDefault
        this.$http.get(url).then(res => {
          res = res.data
          if (res.resultType == 0) {
            let menu = res.result
            this.getMenuList = res.result
            let month = []
            menu.forEach((item) => {
              if (month.indexOf(item.monthWeek) === -1) {
                month.push(item.monthWeek)
              }
              let list = {
                id: item.id.toString(),
                weeklyId: item.weeklyId,
                monthWeek: item.monthWeek
              }
              this.menuList.push(list)

              let weeklyId = item.weeklyId.split('-')
              if (weeklyId[0] <= time && weeklyId[1] >= time) {
                this.weeklyIdDefault = weeklyId.join('-')
                this.menuDefaultId = item.id.toString()
              }
            })
            console.log(this.weeklyIdDefault, this.menuDefaultId)
            this.idDefault = this.menuList[0].id
            this.menu = month.sort(this.sortNumber)
            this.getProjectContent()
          } else {
            this.$notify.error({
              title: '错误',
              message: '服务器异常！'
            });
          }
        })
      },
      addWeekly() {
        if (this.newWeekly.length < 2) {
          this.$notify.error({
            title: '错误',
            message: '请选择周报日期！'
          });
          return
        }
        if (this.newWeekly[0].getDay() != 1 || this.newWeekly[1].getDay() != 5) {
          this.$notify.error({
            title: '错误',
            message: '请选择正确的周报日期！'
          });
          return
        }
        let start = this.newWeekly[0].format('yyyy-MM-dd').split('-')
        let startTime = start.join('')
        let end = this.newWeekly[1].format('yyyy-MM-dd').split('-')
        let endTime = end.join('')
        let weeklyId = startTime + '-' + endTime
        let data = {
          'id': 0,
          'weeklyId': weeklyId,
          'year': start[0],
          'yearWeek': 6,
          'monthWeek': start[1],
          'deptName': this.departmentDefault,
          'oa': null,
          'coordinate': null,
          'projectList': []
        }
        let header = {
          "Content-Type": "application/json;charset=UTF-8"
        }
        let url = this.webUrl + '/weekly/v1/weekly/addOrUpdate.do'

        this.$http.post(url, JSON.stringify(data), {headers: header}).then(res => {
          res = res.data
          this.addWeeklyPopup = false
          if (res.resultType == 0) {
            this.$notify({
              title: '成功',
              message: '添加成功！',
              type: 'success'
            });
            this.getWeeklyList()
          } else {
            this.$notify.error({
              title: '错误',
              message: '服务器异常！'
            });
          }
        })
      },
      handleOpen(key, keyPath) {
      },
      handleClose(key, keyPath) {
      },
      getProjectContent() {
        let url = this.webUrl + '/weekly/v1/weekly/get.do?weeklyId=' + this.weeklyIdDefault + '&deptName=' + this.departmentDefault
        this.$http.get(url).then(res => {
          res = res.data
          if (res.resultType == 0) {
            this.showContent = true
            this.projectList = res.result.projectList
            this.projectList.forEach(item => {
              if (item.content != null) {
                item.content = item.content.split('/')
                let contentList = []
                if (item.content && item.content != '') {
                  item.content.forEach(res => {
                    let i = res.split('!')
                    if (!i[1]) {
                      i[1] = ''
                    }
                    let k = {
                      detail: i[0],
                      time: i[1]
                    }
                    contentList.push(k)
                  })
                } else {
                  let k = {
                    detail: '',
                    time: ''
                  }
                  contentList.push(k)
                }
                item.content = contentList
              }
            })
            this.projectDetail = res.result
          } else {
            this.$notify.error({
              title: '错误',
              message: '服务器异常！'
            });
          }
        })
      },
      handleSelect(key, keyPath) {
        let weekLyId = ''
        this.idDefault = key
        this.getMenuList.forEach(item => {
          if (item.id == key) {
            weekLyId = item.weeklyId
          }
        })
        this.weeklyIdDefault = weekLyId
        this.getProjectContent()
      },
      confirmDel() {
        if (this.weeklyIdDefault == '') {
          this.$notify.error({
            title: '错误',
            message: '请先选择周报！'
          });
        } else {
          this.delWeeklyPopup = true
        }
      },
      delWeekly() {
        let url = this.webUrl + '/weekly/v1/weekly/delete.do?id=' + this.idDefault + '&weeklyId=' + this.weeklyIdDefault
        this.$http.get(url).then(res => {
          res = res.data
          if (res.resultType == 0) {
            this.$notify({
              title: '成功',
              message: '删除成功！',
              type: 'success'
            });
            this.getWeeklyList()
            this.delWeeklyPopup = false
          } else {
            this.$notify.error({
              title: '错误',
              message: '服务器异常！'
            });
          }
        })
      },
      input(index, idx) {
        this.projectList[index].content[idx].flag = true
      },
      addConfirm(workFlag, typeFlag) {
        this.newProjectName = ''
        this.newProjectDetail = [
          {detail: '', time: ''}
        ]
        this.workFlag = workFlag
        this.typeFlag = typeFlag
        this.dialogVisible = true
        this.idDefault = 0
        this.addOrEdit = true
      },
      addNewProjectDetail() {
        let detail = {
          detail: '',
          time: ''
        }
        this.newProjectDetail.push(detail)
      },
      delNewProjectDetail() {
        this.newProjectDetail.splice(this.inputDefault, 1)
      },
      addProject() {
        let content = []
        this.newProjectDetail.forEach(item => {
          if (item.detail.trim() != '') {
            if (item.time == '') {
              content.push(item.detail)
            } else {
              content.push(item.detail + '!' + item.time)
            }
          }
        })
        if (this.newProjectName == '') {
          this.$notify.error({
            title: '错误',
            message: '请输入项目名称！'
          });
          return
        }
        let contentList = ''
        if (content.join('/') == '') {
          contentList = null
        } else {
          contentList = content.join('/')
        }
        let project = {
          'id': this.idDefault,
          'weeklyId': this.weeklyIdDefault,
          'deptName': this.departmentDefault,
          'workFlag': this.workFlag,
          'typeFlag': this.typeFlag,
          'name': this.newProjectName,
          'content': contentList
        }
        let url = this.webUrl + '/weekly/v1/project/add.do'
        let header = {
          "Content-Type": "application/json;charset=UTF-8"
        }
        this.$http.post(url, JSON.stringify(project), {headers: header}).then(res => {
          res = res.data
          if (res.resultType == 0) {
            this.dialogVisible = false
            if (this.addOrEdit) {
              this.$notify({
                title: '成功',
                message: '添加成功！',
                type: 'success'
              });
            } else {
              this.$notify({
                title: '成功',
                message: '修改成功！',
                type: 'success'
              });
            }
            this.getProjectContent()
          } else {
            this.$notify.error({
              title: '错误',
              message: '服务器异常！'
            });
          }
        })
      },
      projectNameModify(index, workFlag, typeFlag) {
        this.workFlag = workFlag
        this.typeFlag = typeFlag
        this.idDefault = this.projectList[index].id
        this.newProjectDetail = []
        this.newProjectName = this.projectList[index].name
        if (this.projectList[index].content == null) {
          this.newProjectDetail = [{
            detail: '',
            time: ''
          }]
        } else {
          this.projectList[index].content.forEach(item => {
            let list = {
              detail: item.detail,
              time: item.time
            }
            this.newProjectDetail.push(list)
          })
        }
        this.dialogVisible = true
        this.addOrEdit = false
      },
      projectNameDeleteConfirm(index) {
        this.delProjectPopup = true
        this.projectNameDefault = this.projectList[index].name
        this.projectIdDefault = this.projectList[index].id
      },
      projectNameDelete() {
        let url = this.webUrl + '/weekly/v1/project/delete.do?id=' + this.projectIdDefault + '&weeklyId=' + this.weeklyIdDefault
        this.$http.get(url).then(res => {
          res = res.data
          if (res.resultType == 0) {
            this.dialogVisible = false
            this.$notify({
              title: '成功',
              message: '项目删除成功！',
              type: 'success'
            });
            this.getProjectContent()
            this.delProjectPopup = false
          } else {
            this.$notify.error({
              title: '错误',
              message: '服务器异常！'
            });
          }
        })
      },
      submit() {
        this.projectList.forEach((item) => {
          if (item.content && item.content != '') {
            let contentList = []
            item.content.forEach(res => {
              let i = ''
              if (res.time == '') {
                i = res.detail
              } else {
                i = res.detail + '!' + res.time
              }
              contentList.push(i)
            })
            item.content = contentList.join('/')
          }
        })
        let data = {
          'id': this.projectDetail.id,
          'weeklyId': this.projectDetail.weeklyId,
          'year': this.projectDetail.year,
          'yearWeek': this.projectDetail.yearWeek,
          'monthWeek': this.projectDetail.monthWeek,
          'deptName': this.projectDetail.deptName,
          'oa': this.projectDetail.oa ? this.projectDetail.oa : '无',
          'coordinate': this.projectDetail.coordinate ? this.projectDetail.coordinate : '无',
          'projectList': this.projectList
        }
        let header = {
          "Content-Type": "application/json;charset=UTF-8"
        }
        let url = this.webUrl + '/weekly/v1/weekly/addOrUpdate.do'

        this.$http.post(url, JSON.stringify(data), {headers: header}).then(res => {
          this.getProjectContent()
          res = res.data
          if (res.resultType == 0) {
            this.$notify({
              title: '成功',
              message: '保存成功！',
              type: 'success'
            });
          } else {
            this.$notify.error({
              title: '保存失败',
              message: '服务器异常！'
            });
          }
        })
      },
      uploadWeekly() {
        window.location.href = this.webUrl + '/weekly/excel/downLoadExcel?weeklyId=' + this.weeklyIdDefault
      }
    }
  }
</script>

<style scoped>

  .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }

  .body {
    height: 100%;
    display: flex;
    justify-content: flex-start;
    flex-wrap: nowrap;
  }

  .menu {
    max-width: 200px;
    min-width: 200px;
    height: 100%;
    background-color: rgb(84, 92, 100);
    overflow-y: auto;
    overflow-x: hidden;
  }

  .menu::-webkit-scrollbar {
    display: none;
  }

  .menu_title {
    height: 100px;
    font-size: 30px;
    font-weight: bold;
    color: #FFF;
    line-height: 100px;
    text-align: center;
  }

  .department {
    text-align: center;
  }

  .content {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .content::-webkit-scrollbar {
    display: none;
  }

  .content_header {
    font-size: 25px;
    height: 60px;
    width: 100%;
    text-align: center;
    line-height: 60px;
    border-bottom: 1px solid rgb(235, 235, 235);
    font-weight: bold;
  }

  .wrapper {
    display: flex;
    justify-content: flex-start;
    text-align: center;
    align-self: flex-end;
    font-weight: bold;
    width: 100%;
    border-bottom: 1px solid rgb(235, 235, 235);
  }

  .content_left {
    flex: 3;
    width: 100%;
    border-right: 1px solid rgb(235, 235, 235);
  }

  .content_right {
    flex: 2;
    width: 100%
  }

  .content_left .title, .content_right .title {
    height: 40px;
    width: 100%;
    font-size: 20px;
    line-height: 40px;
    border-bottom: 1px solid rgb(235, 235, 235);
  }

  .ready {
    height: 30px;
    line-height: 30px;
    font-size: 18px;
    /*border-bottom: 1px solid rgb(235, 235, 235);*/
  }

  .main {
    flex: 1;
    border-right: 1px solid rgb(235, 235, 235);
  }

  .sum_up {
    flex: 1;
  }

  .sum_up, .main {
    height: 30px;
    line-height: 30px;
    font-size: 18px;
    /*border-bottom: 1px solid rgb(235, 235, 235);*/
  }

  .sum_up .project {
    width: 100%;
    font-size: 16px;
    text-align: left;
  }

  .project_detail ul p {
    text-align: left;
    font-size: 15px;
    max-width: 300px;
  }

  .block ul {
    margin-left: 10px;
  }

  .block ul .projectName {
    font-size: 15px;
    text-align: left;
    display: flex;
    justify-content: flex-start;
    align-items: baseline;
  }

  .block ul .projectName p, .block ul .projectName input {
    max-width: 250px;
  }

  .block ul li {
    font-size: 14px;
    text-align: left;
    font-weight: 400;
    padding-left: 10px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }

  .block ul li p {
    width: 300px;
    max-width: 300px;
    word-wrap: break-word;
    word-break: break-all;
  }
</style>